#pragma once
#include <opencv\cv.h>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;
float x_step;
float y_step;
bool editline = false;
int index_edit =0;
struct PoINT
{
	int x;
	int y;
};
class Lines
{
public:
	PoINT start[100];
	PoINT end[100];
	int n;
	Lines(void)
	{
		n =0;
	}

	~Lines(void)
	{
	}
	void Add(int x1,int y1,int x2,int y2)
	{
		start[n].x = x1;
		start[n].y = y1;
		end[n].x = x2;
		end[n].y = y2;
		n++;
	}

	void ShowAll()
	{
		for(int i =0;i<n;i++)
			cout << start[i].x << " " << start[i].y << " : " << end[i].x << " " << end[i].y << endl;
	}
	void DrawAllLine(IplImage* image)
	
	{
		char buff[10];
		
		for(int i =0;i<n;i++)
		{
			if(editline == true && i == index_edit)
			{
			cvLine(image,cvPoint(start[i].x*x_step,start[i].y*y_step),cvPoint(end[i].x*x_step,end[i].y*y_step),cvScalar(255,255,0),1);
			itoa(i,buff,10);
			cvPutText(image,buff,cvPoint((start[i].x*x_step+end[i].x*x_step)/2,(start[i].y*y_step+end[i].y*y_step)/2),&cvFont(2.0,2),cvScalar(255,255,120));
			}
			else
			{
				cvLine(image,cvPoint(start[i].x*x_step,start[i].y*y_step),cvPoint(end[i].x*x_step,end[i].y*y_step),cvScalar(255,0,0),3);
			itoa(i,buff,10);
			cvPutText(image,buff,cvPoint((start[i].x*x_step+end[i].x*x_step)/2,(start[i].y*y_step+end[i].y*y_step)/2),&cvFont(2.0,2),cvScalar(255,120,0));
			}
		}
		cvShowImage("test",image);
	}
	void Save(char* name)
	{
		fstream f;
		f.open(name,ios::app);
		f << n << endl;
		for(int i =0;i<n;i++)
			f << start[i].x << " " << start[i].y << " " << end[i].x << " " << end[i].y << endl;
		f.close();
	}
	void Load(char* name)
	{
		fstream f;
		f.open(name,ios::in);
		f >> n;
		for(int i =0;i<n;i++)
		{
			//f << start[i].x << " " << start[i].y << " " << end[i].x << " " << end[i].y << endl;
			f >> start[i].x;
			f >> start[i].y;
			f >> end[i].x;
			f >> end[i].y;
		}
		f.close();
	}
};

